﻿$(function(){
	//当日可发送短信次数
	var i = 5;
	//发送倒计时
	var num = 60;
	
	//定时器
	function timer(){
		var timeData  = setInterval(function(){ 
			//倒计时
			if(num > 1){
				$(".validateCode").attr("disabled","disabled");
				num -= 1;
				$(".validateCode").text("还剩" + num + "秒");
			}else{
				//关闭倒计时
				$(".validateCode").attr('disabled',false);
				$(".validateCode").text("获取验证码");
				num = 60;
				clearInterval(timeData);
				return;
			}
		},1000);
	}
	
	//获取验证码
	$(".validateCode").on("click",function(){
		if(i > 0){
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("提示");
			$(".modal-body").text("验证码发送成功!");
			timer();
			i -= 1;
		}else{
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("错误提示");
			$(".modal-body").text("今日可发送次数已达上限!");
			i = 0;
		}	
	});
	
	//登录
	$(".login").on("click",function(){
		$("#myModel").attr("aria-hidden","true");
		var phoneNumber = $("#phoneNumber").val();
		var validateCode = $("#validateCode").val();
		if(null != phoneNumber && phoneNumber != ""){
			if(null != validateCode && validateCode != ""){
				window.location.href="../pages/member.html";
			}else{
				$("#myModel").attr("aria-hidden","false");
				$("#myModalLabel").text("错误提示");
				$(".modal-body").text("验证码不能为空!");
			}
		}else{
			$("#myModel").attr("aria-hidden","false");
			$("#myModalLabel").text("错误提示");
			$(".modal-body").text("手机号不能为空!");
		}
	});
	
	//跳转注册页面
	$(".register").on("click",function(){
		window.location.href="../pages/register.html";
	});
})